<style>
    .layui-table-cell {
        height: auto;
    }

    div[lay-id="addSelfCollectedGoodsTableModifyList"] .layui-table-cell {
        overflow: visible;
        padding: 0 5px;
    }

    div[lay-id="addSelfCollectedGoodsTable"] .layui-table-cell,
    div[lay-id="addSelfCollectedGoodsTable"] .layui-form,
    div[lay-id="addSelfCollectedGoodsTable"] .layui-table-box,
    div[lay-id="addSelfCollectedGoodsTable"] .layui-table-body,
    div[lay-id="addSelfCollectedGoodsTableModifyList"] .layui-form,
    div[lay-id="addSelfCollectedGoodsTableModifyList"] .layui-table-box,
    div[lay-id="addSelfCollectedGoodsTableModifyList"] .layui-table-body,
    div[lay-id="addSelfCollectedGoodsTableList"] .layui-table-cell {
        overflow: visible;
        padding: 0 5px;
    }

</style>
<!-- 正文开始 -->
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body">
            <!-- 头部操作栏 -->
            <div class="layui-form toolbar">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <button class="layui-btn icon-btn" lay-filter="formSubSearchLog" lay-submit><i class="layui-icon">&#xe615;</i>搜索</button>
                        <button id="productDetailSKUBtnAdd" class="layui-btn icon-btn"><i class="layui-icon">&#xe654;</i>添加</button>
                        <button id="productDetailSKUBtnExport" class="layui-btn icon-btn"><i class="layui-icon">&#xe67d;</i>导出</button>
                    </div>
                </div>
            </div>
            <!-- 表格 -->
            <table class="layui-table" id="productDetailSKUTable" lay-filter="productDetailSKUTable"></table>
        </div>
    </div>
</div>

<!-- 入库弹窗 -->
<script type="text/html" id="storageForm">
    <form class="layui-form" action="" lay-filter="storageForm">
        <input name="skuCode" id="skuCode" type="hidden"/>
        <div class="layui-form-item" style="margin-top: 6px;">
            <div class="layui-form-item">
                <label class="layui-form-label" style="width: 100px;padding-left: 0px;"><span
                        style="color: red">*</span>入库仓库</label>
                <div class="layui-input-block" style="width: 200px;margin-left: 115px;">
                    <select name="warehouseId" required lay-verify="required" id="warehouseIdOption" placeholder="请选择入库仓库">
                        <option value="">选择入库仓库</option>
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">入库数量</label>
                <div class="layui-input-block" style="width: 200px;margin-left: 115px;">
                    <input name="quantity" placeholder="请输入入库数量" type="text" class="layui-input" lay-verify="required" required/>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit lay-filter="storageFormSubmit">提交</button>
                </div>
            </div>
        </div>
    </form>
</script>
<!-- 数据同步到云端表单弹窗 -->
<script type="text/html" id="synsSkuForm">
    <form lay-filter="synsSkuForm" class="layui-form model-form formBg" style="padding:20px;">
        <div class="layui-card-body">
            <input type="hidden" name="enterpriseCode" id="enterpriseCode" value="">
            <div class="layui-row">
                <div class="layui-col-md4 conentStyle">
                    <div class="conentBg">
                        <div class="layui-form-item">
                            <label class="layui-form-label w-120">企业物料图片:</label>
                            <div class="layui-input-inline">
                                <input type="hidden" name="enterpriseItemPic" id="enterpriseItemPic" value=""/>
                                <img src="" style="height: 135px;width: 135px" id="enterprisePic"/>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label w-120">企业物料名称:</label>
                            <div class="layui-input-inline">
                                <input name="enterpriseName" id="enterpriseName" class="layui-input borderNone"
                                       type="text" disabled/>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label w-120">企业物料编码</label>
                            <div class="layui-input-inline">
                                <input name="enterpriseProductCode" id="enterpriseProductCode"
                                       class="layui-input borderNone" type="text" disabled/>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label w-120">企业物料类型</label>
                            <div class="layui-input-inline">
                                <input name="enterpriseProductType" id="enterpriseProductType"
                                       class="layui-input borderNone" type="text" disabled/>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label w-120">企业物料分类</label>
                            <div class="layui-input-inline">
                                <input name="enterpriseProductCategory" id="enterpriseProductCategory"
                                       class="layui-input borderNone" type="text" disabled/>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label w-120">企业物料扩展分类</label>
                            <div class="layui-input-inline">
                                <input name="enterpriseProductCategoryExt" id="enterpriseProductCategoryExt"
                                       class="layui-input borderNone" type="text" disabled/>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label w-120">企业品牌</label>
                            <div class="layui-input-inline">
                                <input name="enterpriseBrand" id="enterpriseBrand" class="layui-input borderNone"
                                       type="text" disabled/>
                            </div>
                        </div>
                        <!--<div class="layui-form-item">
                            <label class="layui-form-label w-120">企业物料属性</label>
                            <div class="layui-input-block">
                                <div class="layui-input-inline mr0" style="width: 260px;" id="enterpriseProductAttrHtml"
                                     name="enterpriseProductAttrHtml"></div>
                                <div id="enterpriseProductAttrValueHtml" name="enterpriseProductAttrValueHtml"></div>
                            </div>
                        </div>-->
                    </div>
                </div>
                <div class="layui-col-md8 conentStyle">
                    <div class="conentBg">
                        <div class="layui-form-item">
                            <label class="layui-form-label w-120">平台物料图片:</label>
                            <div class="layui-input-inline" style="width: 260px;">
                                <div id="btnUpload1Syns_path" style="float: left;"></div>
                                <div id="btnUpload1Syns" class="layui-btn" style="float: left;"><i class="layui-icon">&#xe681;</i>上传图片
                                </div>
                                <input id="pictureSyns" name="pictureSyns" type="hidden"/>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label w-120">平台物料名称</label>
                            <div class="layui-input-inline">
                                <input name="platformName" id="platformName" class="layui-input" type="text"
                                       placeholder="请输入物料名称"/>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label w-120">平台物料编码</label>
                            <div class="layui-input-inline">
                                <input name="platformProductCode" id="platformProductCode" class="layui-input"
                                       type="text" placeholder="请输入物料编码" disabled/>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label w-120">平台物料类型</label>
                            <div class="layui-input-inline">
                                <select lay-filter="platformProductTypeId" id="platformProductTypeId"
                                        name="platformProductTypeId" lay-verify="required">
                                    <option value="">请选择物料类型</option>
                                </select>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label w-120">平台物料分类</label>
                            <input name="platformProductCategoryId" value="" type="hidden">
                            <div class="layui-input-block mr0" id="platformProductCategoryId"
                                 style="margin-left: 150px;"></div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label w-120">平台物料扩展分类</label>
                            <input name="platformProductCategoryIdExt" value="" type="hidden">
                            <div class="layui-input-block mr0" id="platformProductCategoryExt"
                                 style="margin-left: 150px;"></div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label w-120">平台品牌</label>
                            <div class="layui-input-inline">
                                <select lay-filter="platformBrandId" id="platformBrandId" name="platformBrandId"
                                        lay-verify="required">
                                    <option value="">请选择品牌</option>
                                </select>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label w-120">平台物料单位</label>
                            <div class="layui-input-inline">
                                <select lay-filter="platformUnitId" id="platformUnitId" name="platformUnitId"
                                        lay-verify="required">
                                    <option value="">请选择单位</option>
                                </select>
                            </div>
                        </div>
                        <!--<div class="layui-form-item">
                            <label class="layui-form-label w-120">平台物料属性</label>
                            <div class="layui-input-block">
                                <div class="layui-input-inline mr0" id="platformProductAttrHtml"
                                     name="platformProductAttrHtml"></div>
                                <div id="platformProductAttrValueHtml" name="platformProductAttrValueHtml"></div>
                            </div>
                        </div>-->
                    </div>
                </div>
            </div>

            <!-- <div class="layui-row">
                <div class="layui-col-xs6">
                    <div class="grid-demo grid-demo-bg1 title-txt">企业物料信息</div>
                </div>
                <div class="layui-col-xs6">
                    <div class="grid-demo title-txt">同步到平台的物料信息</div>
                </div>
            </div>
            <div class="layui-row">
                <div class="layui-col-xs6">
                    <label class="layui-form-label layui-col-sm3 w-120">企业物料图片</label>
                    <div class="layui-input-inline">
                        <input type="hidden" name="enterpriseItemPic" id ="enterpriseItemPic" value=""/>
                        <img src="" style="height: 135px;width: 135px" id="enterprisePic"/>
                    </div>
                </div>
                <div class="layui-col-xs6">
                    <label class="layui-form-label w-120">平台物料图片</label>
                    <div class="layui-input-inline">
                        <div id="btnUpload1Syns" class="layui-btn" style="float: left;"><i class="layui-icon">&#xe681;</i>上传图片</div>
                        <div id="btnUpload1Syns_path" style="margin-left: 260px;line-height: 40px;"></div>
                        <input id="pictureSyns" name="pictureSyns" type="hidden"/>
                    </div>
                </div>
            </div>
            <div class="layui-row">
                <div class="layui-col-xs6">
                    <label class="layui-form-label w-120">企业物料名称</label>
                    <div class="layui-input-inline">
                        <input name="enterpriseName" id = "enterpriseName" class="layui-input" type="text" disabled/>
                    </div>
                </div>
                <div class="layui-col-xs6">
                    <label class="layui-form-label w-120">平台物料名称</label>
                    <div class="layui-input-inline">
                        <input name="platformName" id = "platformName" class="layui-input" type="text" placeholder="请输入物料名称"/>
                    </div>
                </div>
            </div>
            <div class="layui-row">
                <div class="layui-col-xs6">
                    <label class="layui-form-label w-120">企业物料编码</label>
                    <div class="layui-input-inline">
                        <input name="enterpriseProductCode" id = "enterpriseProductCode" class="layui-input" type="text" disabled/>
                    </div>
                </div>
                <div class="layui-col-xs6">
                    <label class="layui-form-label w-120">平台物料编码</label>
                    <div class="layui-input-inline">
                        <input name="platformProductCode" id="platformProductCode" class="layui-input" type="text" placeholder="请输入物料编码"/>
                    </div>
                </div>
            </div>
            <div class="layui-row">
                <div class="layui-col-xs6">
                    <label class="layui-form-label w-120">企业物料类型</label>
                    <div class="layui-input-inline">
                        <input name="enterpriseProductType" id="enterpriseProductType" class="layui-input" type="text" disabled/>
                    </div>
                </div>
                <div class="layui-col-xs6">
                    <label class="layui-form-label w-120">平台物料类型</label>
                    <div class="layui-input-inline">
                        <select lay-filter="platformProductTypeId" id="platformProductTypeId" name="platformProductTypeId" lay-verify="required">
                            <option value="">请选择物料类型</option>
                        </select>
                    </div>
                </div>
            </div>
            <div class="layui-row">
                <div class="layui-col-xs6">
                    <label class="layui-form-label w-120">企业物料分类</label>
                    <div class="layui-input-inline">
                        <input name="enterpriseProductCategory" id="enterpriseProductCategory" class="layui-input" type="text" disabled/>
                    </div>
                </div>
                <div class="layui-col-xs6">
                    <label class="layui-form-label w-120">平台物料分类</label>
                    <input name="platformProductCategoryId" value="" type="hidden">
                    <div class="layui-input-block mr0" id="platformProductCategoryId" style="margin-left: 150px;">
                    </div>
                </div>
            </div>
            <div class="layui-row">
                <div class="layui-col-xs6">
                    <label class="layui-form-label w-120">企业物料扩展分类</label>
                    <div class="layui-input-inline">
                        <input name="enterpriseProductCategoryExt" id="enterpriseProductCategoryExt" class="layui-input" type="text" disabled/>
                    </div>
                </div>
                <div class="layui-col-xs6">
                    <label class="layui-form-label w-120">平台物料扩展分类</label>
                    <input name="platformProductCategoryIdExt" value="" type="hidden">
                    <div class="layui-input-block mr0" id="platformProductCategoryExt" style="margin-left: 150px;">
                    </div>
                </div>

            </div>
            <div class="layui-row">
                <div class="layui-col-xs6">
                    <label class="layui-form-label w-120">企业品牌</label>
                    <div class="layui-input-inline">
                        <input name="enterpriseBrand" id="enterpriseBrand" class="layui-input" type="text" disabled/>
                    </div>
                </div>
                <div class="layui-col-xs6">
                    <label class="layui-form-label w-120">平台品牌</label>
                    <div class="layui-input-inline">
                        <select lay-filter="platformBrandId" id="platformBrandId" name="platformBrandId" lay-verify="required">
                            <option value="">请选择品牌</option>
                        </select>
                    </div>
                </div>

            </div>
            <div class="layui-row">
                <div class="layui-col-xs6">
                    <label class="layui-form-label w-120">企业物料属性</label>
                    <div class="layui-input-block">
                        <div class="layui-input-inline mr0" id="enterpriseProductAttrHtml" name = "enterpriseProductAttrHtml">

                        </div>
                        <div id = "enterpriseProductAttrValueHtml" name = "enterpriseProductAttrValueHtml">

                        </div>
                    </div>
                </div>
                <div class="layui-col-xs6">
                    <label class="layui-form-label w-120">平台物料属性</label>
                    <div class="layui-input-block">
                        <div class="layui-input-inline mr0" id="platformProductAttrHtml" name = "platformProductAttrHtml">

                        </div>
                        <div id = "platformProductAttrValueHtml" name = "platformProductAttrValueHtml">

                        </div>
                    </div>
                </div>

            </div> -->
            <table class="layui-table" id="platformProductSkuTable" name="platformProductSkuTable"
                   lay-filter="platformProductSkuTable"></table>
        </div>
    </form>
</script>
<!-- 表格操作列 -->
<script type="text/html" id="productDetailSKUTableBar">
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="storageBtn">入库</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="synsSku">同步到云端</a></a>
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="edit">修改</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>

<!-- 表单弹窗 -->
<script type="text/html" id="productDetailSKUForm">
    <form lay-filter="productDetailSKUForm" class="layui-form model-form">
        <input name="id" type="hidden"/>
        <div class="layui-form-item">
            <label class="layui-form-label">物料名称</label>
            <div class="layui-input-block">
                <input name="skuName" placeholder="请输入物料名称" type="text" class="layui-input" lay-verify="required" required/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">物料编号</label>
            <div class="layui-input-block">
                <input name="skuCode" placeholder="请输入物料编号" type="text" class="layui-input" lay-verify="required" required/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">商品缩略图</label>
            <div class="layui-input-block">
                <input name="productPic" placeholder="请输入商品缩略图" type="text" class="layui-input" lay-verify="required" required/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">商品规格</label>
            <div class="layui-input-block">
                <input name="skuSpec" placeholder="请输入商品规格" type="text" class="layui-input" lay-verify="required" required/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">企业货号</label>
            <div class="layui-input-block">
                <input name="enterpriceCode" placeholder="请输入企业货号" type="text" class="layui-input" lay-verify="required" required/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">市场指导价</label>
            <div class="layui-input-block">
                <input name="marketPrice" placeholder="请输入市场指导价" type="text" class="layui-input" lay-verify="required" required/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">商品店铺价</label>
            <div class="layui-input-block">
                <input name="storePrice" placeholder="请输入商品店铺价" type="text" class="layui-input" lay-verify="required" required/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">最低活动价</label>
            <div class="layui-input-block">
                <input name="activityPrice" placeholder="请输入最低活动价" type="text" class="layui-input" lay-verify="required" required/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">平台供货价</label>
            <div class="layui-input-block">
                <input name="supplyPrice" placeholder="请输入平台供货价" type="text" class="layui-input" lay-verify="required" required/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">库存数</label>
            <div class="layui-input-block">
                <input name="stockNumber" placeholder="请输入库存数" type="text" class="layui-input" lay-verify="required" required/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">商品条码</label>
            <div class="layui-input-block">
                <input name="barcode" placeholder="请输入商品条码" type="text" class="layui-input" lay-verify="required" required/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">排序</label>
            <div class="layui-input-block">
                <input name="sortNumber" placeholder="请输入排序" type="text" class="layui-input" lay-verify="required" required/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">入驻企业ID</label>
            <div class="layui-input-block">
                <input name="settledCompanyId" placeholder="请输入入驻企业ID" type="text" class="layui-input" lay-verify="required" required/>
            </div>
        </div>
        <div class="layui-form-item text-right">
            <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
            <button class="layui-btn" lay-filter="productDetailSKUFormSubmit" lay-submit>保存</button>
        </div>
    </form>
</script>
<!--新 添加自采商品-->
<!--addSelfCollectedGoods-->
<script type="text/html" id="addSelfCollectedGoods">
    <form lay-filter="addSelfCollectedGoodsForm" class="layui-form model-form addSelfCollectedGoodsForm"
          style="padding: 5px 10px 0;height: calc(100% - 5px);overflow: hidden;">
        <div class="open-details-box" style="height: calc(100% - 75px);">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">选择类型：</label>
                    <div class="layui-input-inline">
                        <select name="addSelfCollectedGoodsProductTypeId" lay-verify="required"
                                id="addSelfCollectedGoodsProductTypeId"
                                lay-filter="addSelfCollectedGoodsProductTypeId"></select>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">选择分类：</label>
                    <div class="layui-input-inline">
                        <input name="addSelfCollectedGoodsProductCategoryId" type="hidden" lay-verify="required">
                        <div class="layui-input-inline mr0" id="addSelfCollectedGoodsProductCategoryId"></div>
                    </div>
                </div>

                <div class="layui-inline">
                    <label class="layui-form-label">所属品牌：</label>
                    <div class="layui-input-inline">
                        <select name="addSelfCollectedGoodsBrandId"
                                id="addSelfCollectedGoodsBrandId" lay-filter="addSelfCollectedGoodsBrandId"></select>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">物料系列：</label>
                    <div class="layui-input-inline">
                        <select name="addSelfCollectedGoodsProductId"
                                id="addSelfCollectedGoodsProductId" lay-filter="addSelfCollectedGoodsProductId"></select>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">基础计量单位：</label>
                    <div class="layui-input-inline">
                        <select name="addSelfCollectedGoodsUnitId"
                                id="addSelfCollectedGoodsUnitId" lay-filter="addSelfCollectedGoodsUnitId"></select>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">物资来源：</label>
                    <div class="layui-input-inline">
                        <select name="addSelfCollectedGoodsProduceId"
                                id="addSelfCollectedGoodsProduceId" lay-filter="addSelfCollectedGoodsProduceId">
                            <option value="0">外部采购</option>
                            <option value="1">自产</option>
                        </select>
                    </div>
                </div>
               <!-- <div class="layui-inline addSelfCollectedGoodsNumBox">
                    <label class="layui-form-label ">添加规格数：</label>
                    <div class="layui-input-inline">
                        <input id="addSelfCollectedGoodsNum" class="layui-input" type="text" lay-verify="required"
                               onkeyup="value=value.replace(/^(0+)|[^\d]+/g,'')"/>
                    </div>
                </div>-->

            </div>
            <div class="layui-form-item addSelfCollectedGoodsPictureBox">
                <label class="layui-form-label ">图片：</label>
                <div class="layui-inline">
                    <div id="addSelfCollectedGoodsPicture_path" class="uploadImgStyle"></div>
                    <div id="addSelfCollectedGoodsPictureBtn" class="layui-btn" style="float: left;">上传图片</div>
                    <input name="addSelfCollectedGoodsPicture" type="hidden" class="layui-input"
                           id="addSelfCollectedGoodsPicture"/>
                </div>
            </div>

            <div class="layui-row addSelfCollectedGoodsTableListBox" style="margin-top: 20px">
                <table class="layui-table" id="addSelfCollectedGoodsTableList"
                       lay-filter="addSelfCollectedGoodsTableList"></table>
            </div>

            <div class="layui-row">
                <table class="layui-table" id="addSelfCollectedGoodsTableModifyList"
                       lay-filter="addSelfCollectedGoodsTableModifyList"></table>
                <div class="layui-form-item">
                    <div class="layui-inline addSelfCollectedGoodsTableModifyListUploadImgBox">
                        <div id="addSelfCollectedGoodsTableModifyListUploadImg_path" class="uploadImgStyle"></div>
                        <div lay-event="addSelfCollectedGoodsTableModifyListUploadImgBtn"
                             id="addSelfCollectedGoodsTableModifyListUploadImgBtn" class="layui-btn"
                             style="float: left;">上传sku图片
                        </div>
                        <input name="addSelfCollectedGoodsTableModifyListUploadImg" type="hidden" class="layui-input"
                               lay-verify=""
                               id="addSelfCollectedGoodsTableModifyListUploadImg"/>
                    </div>

                </div>
            </div>
        </div>
        <div class="layui-form-item text-right">
            <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
            <button class="layui-btn" type="button" lay-filter="addSelfCollectedGoodsSubmit"
                    id="addSelfCollectedGoodsSubmit" lay-submit>提交
            </button>
        </div>
    </form>
</script>

<!--新 添加自采  addSelfCollectedGoodsTableListBar -->
<script type="text/html" id="addSelfCollectedGoodsTableListBar">
    {{# if(d.isShow==true){  }}
    <a class="layui-btn layui-btn-xs" lay-event="save">保存</a>
    {{# }else{ }}
    <a class="layui-btn layui-btn-xs layui-btn-primary" lay-event="modify">修改</a>
    {{# } }}
</script>
<!-- js部分 -->
<script>
    layui.use(['layer', 'form', 'table', 'admin','upload'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var table = layui.table;
        var config = layui.config;
        var admin = layui.admin;
        var upload = layui.upload;

        // 渲染表格
        var insTb = table.render({
            elem: '#productDetailSKUTable',
            url: config.base + 'enterprise/product/admin/productDetailSKU/list',
            page: true,
            cellMinWidth: 100,
            cols: [[
                {type: 'checkbox'}
                , {
                    field: 'productPic',
                    title: '图片',
                    event: 'imgClick',
                    templet: (d) => "<img src='" + d.productPic + "' width='80px' height='80px'/>"
                }
                , {field: 'skuCode', title: '物料编号'}
                , {field: 'oldSpecCode', title: '规格码'}
                , {field: 'productCode', title: '物料系列编号'}
                , {field: 'productTypeName', title: '物料类型'}
                , {field: 'weightNumber', title: '重量'}
                ,{field: 'deleted', sort: true, title: '是否启用',templet:function (d) {
                        if(d.deleted){
                            return '<input name="deleted" type="checkbox" lay-skin="switch" value="'+d.id+'" checked="'+d.deleted+'" lay-filter="deleted"  lay-text="启用|停用"/>';
                        }else{
                            return '<input name="deleted" type="checkbox" lay-skin="switch" value="'+d.id+'" lay-filter="deleted"   lay-text="启用|停用"/>';
                        }
                    }}
                ,{field: 'isSyns', sort: true, title: '是否同步到云端',templet:function (d) {
                        if(d.isSyns){
                            return '是';
                        }else{
                            return '否';
                        }
                    }}
                ,{field: 'synsTime', sort: true, title: '同步时间'}
                ,{align: 'center', toolbar: '#productDetailSKUTableBar', title: '操作', width: 260}
            ]],
            done: function (res, curr, count) {
                //移除按钮
                var menuButton = config.getMenuButton(location.hash);
                if(menuButton.indexOf("搜索") == -1){
                    $('.layui-form.toolbar').remove();
                }
                if(menuButton.indexOf("修改") == -1){
                    $("[lay-event='edit']").remove();
                }
                if(menuButton.indexOf("删除") == -1){
                    $("[lay-event='del']").remove();
                }
            }
        });

        // 工具条点击事件
        table.on('tool(productDetailSKUTable)', function (obj) {
            var data = obj.data;
            if (obj.event === 'edit') { //修改
                showEditModel(data);
            } else if (obj.event === 'del') { // 删除
                doDelete(obj);
            }else if (obj.event === 'storageBtn') { // 入库
                showStorageModel(obj);
            }else if(obj.event ==='synsSku'){
                doSynsSku(obj);
            }
        });

        //监听排序
        table.on('sort(productDetailSKUTable)', function(obj){
            table.reload('productDetailSKUTable', {
                initSort: obj
                ,where: {
                    sort: obj.field
                    ,order: obj.type
                }
            });
        });


        // 同步SKU到平台
        function doSynsSku(obj) {
            console.log(obj.data)
            var data = obj.data;
            admin.open({
                type: 1,
                area: '1600px',
                offset: '65px',
                title: '同步物料到云端',
                content: $('#synsSkuForm').html(),
                success: function () {

                    //查询企业信息
                    var enterpriseInfo;
                    admin.req('enterprise/system/admin/enterpricceId/getEnterpricceIdVO', {}, function (res) {
                        enterpriseInfo = res.data;
                    }, 'get', false);

                    $("#enterprisePic").attr("src", data.picture);
                    $("#enterpriseItemPic").val(data.picture);
                    $("#enterpriseName").val(data.name);
                    $("#enterpriseProductCode").val(data.productCode);
                    $("#enterpriseProductType").val(data.productTypeName);
                    $("#enterpriseProductCategory").val(data.productCategoryName);
                    $("#enterpriseProductCategoryExt").val(data.productCategoryExtName);
                    $("#enterpriseBrand").val(data.brandName);
                    $("#enterpriseCode").val(data.enterpriseCode);
                    //$("#platformProductCode").val(data.enterpriseCode +"_"+ data.productCode);
                    $("#platformProductCode").val(enterpriseInfo.enterpriseCode + "_" + data.productCode);
                    $("#platformName").val(data.name);
                    $('#btnUpload1Syns_path').html('<img src="' + data.productPic + '" style="height: 135px;width: 135px" />');
                    $('#pictureSyns').val(data.picture);

                    //回显商品属性
                    admin.req('enterprise/product/admin/productAttribute/getProductAttrByProductTypeId', {productTypeId: data.productTypeId}, function (res) {
                        createEnterpriseProductAttr(res.data);
                    }, 'get', false);

                    console.log(data)
                    for (var k = 0; k < data.productDetailAttribute.length; k++) {
                        var attrObj = data.productDetailAttribute[k];
                        var arrrValueObj = attrObj.productDetailAttributeValue;
                        if (attrObj.style == 'single') {
                            $("#enterpriseProductAttrValue" + attrObj.attrId).val(arrrValueObj[0].valueId);
                        }
                        if (attrObj.style == 'many') {
                            var checkboxArr = $("input[name='enterpriseProductAttrValue" + attrObj.attrId + "']");
                            for (let j = 0; j < checkboxArr.length; j++) {
                                for (var i = 0; i < arrrValueObj.length; i++) {
                                    if ($(checkboxArr[j]).val() == arrrValueObj[i].valueId) {
                                        $(checkboxArr[j]).prop("checked", "checked")
                                    }
                                }
                            }
                        }
                        if (attrObj.style == 'text') {
                            $("#enterpriseProductAttrValue" + attrObj.attrId).val(attrObj.attrValue);
                        }
                    }
                    form.render();

                    //加载物料类型
                    admin.req('enterprisecab/productCab/admin/product/getProductTypeByType', {type: 0}, function (res) {
                        loadSelectHtml(res.data.data, "请选择物料类型", "platformProductTypeId", "name");
                    }, 'get', false);

                    //加载物料分类树级菜单
                    var arr2tree;
                    admin.req('enterprisecab/productCab/admin/product/getProductCategoryByType', {type: 0}, function (res) {
                        if (res.code == 200) {
                            for (let i = 0; i < res.data.length; i++) {
                                res.data[i].children = [];
                            }
                            arr2tree = xmSelect.arr2tree(res.data, "parentId", "id", "children", -1);
                        }
                    }, 'get', false);


                    var smlSelectInstans = xmSelect.render({
                        el: '#platformProductCategoryId',
                        model: {label: {type: 'text'}},
                        radio: true,
                        clickClose: true,
                        filterable: true,
                        tree: {
                            show: true,
                            strict: false,
                            expandedKeys: [-1],
                        },
                        tips: '顶级分类',
                        prop: {
                            name: 'name',
                            value: 'id',
                            children: 'children'
                        },
                        data() {
                            //填充数据
                            return arr2tree;
                        },
                        on(data) {
                            let parentId = data.arr.length > 0 ? data.change[0].id : -1;
                            $("input[name='platformProductCategoryId']").val(parentId);
                        }
                    });
                    //加载扩展物料分类树级菜单
                    var arr2treeExt;
                    admin.req('enterprisecab/productCab/admin/product/getProductCategoryByType', {type: 0}, function (res) {
                        if (res.code == 200) {
                            for (let i = 0; i < res.data.length; i++) {
                                res.data[i].children = [];
                            }
                            arr2treeExt = xmSelect.arr2tree(res.data, "parentId", "id", "children", -1);
                        }
                    }, 'get', false);

                    var smlSelectInstansExt = xmSelect.render({
                        el: '#platformProductCategoryExt',
                        model: {label: {type: 'text'}},
                        //radio: true,
                        clickClose: true,
                        filterable: true,
                        tree: {
                            show: true,
                            strict: false,
                            expandedKeys: [-1],
                        },
                        tips: '顶级分类',
                        prop: {
                            name: 'name',
                            value: 'id',
                            children: 'children'
                        },
                        data() {
                            //填充数据
                            return arr2treeExt;
                        },
                        on: function (data) {
                            var id = '';
                            for (var j = 0; j < data.arr.length; j++) {
                                if (j == 0) {
                                    id = data.arr[j].id
                                } else {
                                    id += ',' + data.arr[j].id;
                                }
                            }
                            $("input[name='platformProductCategoryIdExt']").val(id)
                        }
                    });

                    //加载品牌
                    admin.req('enterprisecab/productCab/admin/product/getProductBrandByType', {type: 0}, function (res) {
                        loadSelectHtmlByCode(res.data, "请选择品牌", "platformBrandId", "name");
                    }, 'get', false);

                    var productAttrData;

                    form.on('select(platformProductTypeId)', function (data) {
                        admin.req('enterprisecab/productCab/admin/product/getProductAttrByProductTypeId', {productTypeId: data.value}, function (res) {
                            productAttrData = res.data;
                        }, 'get', false);
                        //创建物料属性
                        createPlatformProductAttr(productAttrData);

                        //加载物料单位
                        admin.req('enterprisecab/productCab/admin/product/getProductUnitByType', {
                            type: 0,
                            productTypeId: data.value
                        }, function (res) {
                            loadSelectHtmlByCode(res.data, "请选择单位", "platformUnitId", "name");
                        }, 'get', false);
                    });
                    function createPlatformProductAttr(data) {
                        let html = '';
                        if (!data || data == null) {
                            return;
                        }
                        for (let i = 0; i < data.length; i++) {
                            //多选
                            if (data[i].style == 'many') {
                                html += '<div style="margin-top: 20px" name="attrValue' + data[i].name + '">';
                                html += '<div class="layui-form-item">';
                                html += '<label class="layui-form-label" style="padding-left: 0;text-align: left;">' + data[i].name + ':</label>';
                                html += '<div class="layui-input-block">';

                                for (let j = 0; j < data[i].productAttributeValue.length; j++) {
                                    var subData = data[i].productAttributeValue[j];
                                    html += '<input lay-filter="platformProductAttrValue' + data[i].id + '" type="checkbox" name  = "platformProductAttrValue' + data[i].id + '"  value="' + subData.id + '" lay-skin="primary" title="' + subData.value + '">';
                                }
                                html += '</div>';
                                html += '</div>';
                                html += '</div>';
                            }
                            //单选
                            if (data[i].style == 'single') {
                                html += '<div style="margin-top: 20px" name="attrValue' + data[i].name + '">';
                                html += '<div class="layui-form-item">';
                                html += '<label class="layui-form-label" style="padding-left: 0;text-align: left;">' + data[i].name + ':</label>';
                                html += '<div class="layui-input-block">';
                                html += '<select lay-filter="platformProductAttrValue' + data[i].id + '"  name="platformProductAttrValue' + data[i].id + '" id="platformProductAttrValue' + data[i].id + '" lay-verify="required">';
                                html += '<option value="">请选择属性</option>';
                                for (let j = 0; j < data[i].productAttributeValue.length; j++) {
                                    var subData = data[i].productAttributeValue[j];
                                    html += '<option value="' + subData.id + '">' + subData.value + '</option>';
                                }
                                html += "</select>";
                                html += '</div>';
                                html += '</div>';
                                html += '</div>';
                            }
                            //文本
                            if (data[i].style == 'text') {
                                html += '<div style="margin-top: 20px" name="attrValue' + data[i].name + '">';
                                html += '<div class="layui-form-item">';
                                html += '<label class="layui-form-label" style="padding-left: 0;text-align: left;">' + data[i].name + ':</label>';
                                html += '<div class="layui-input-block">';
                                html += '<input type="text" class="layui-input" lay-filter="platformProductAttrValue' + data[i].id + '" name="platformProductAttrValue' + data[i].id + '" id="platformProductAttrValue' + data[i].id + '" lay-verify="required" />';
                                html += '</div>';
                                html += '</div>';
                                html += '</div>';
                            }
                        }
                        //console.log(html);
                        $("[name='platformProductAttrHtml']").html(html);
                        form.render();

                    }
                    // for(var k=0;k<data.productDetailAttribute.length;k++){
                    //     var attrObj = data.productDetailAttribute[k];
                    //     var arrrValueObj = attrObj.productDetailAttributeValue;
                    //     if(attrObj.style == 'single'){
                    //         $("#platformProductAttrValue" + attrObj.attrId).val(arrrValueObj[0].valueId);
                    //     }
                    //     if(attrObj.style == 'many'){
                    //         var checkboxArr = $("input[name='platformProductAttrValue"+ attrObj.attrId+"']");
                    //         for (let j = 0; j < checkboxArr.length; j++) {
                    //             for(var i=0;i<arrrValueObj.length;i++){
                    //                 if ($(checkboxArr[j]).val() == arrrValueObj[i].valueId) {
                    //                     $(checkboxArr[j]).prop("checked", "checked")
                    //                 }
                    //             }
                    //         }
                    //     }
                    //     if(attrObj.style == 'text'){
                    //         $("#platformProductAttrValue" + attrObj.attrId).val(attrObj.attrValue);
                    //     }
                    // }
                    //form.render();

                    upload.render({
                        elem: '#btnUpload1Syns'
                        , url: config.upload_url + 'upload?path=' + img_path
                        , data: {"path": enterpriseInfo.enterpriseCode + "/"}
                        , accept: 'file'
                        , exts: 'jpg|png|RAR|zip|pdf|txt|doc|docx|xls|xlsx|ppt|pptx'
                        , headers: {Authorization: 'Bearer ' + config.getToken()}
                        , done: function (res) {
                            if (res.code == 200) {
                                layer.msg(res.msg || "上传成功", {icon: 1});
                                var imagUrl = res.data.url;
                                // if(imagUrl){
                                //     imagUrl=imagUrl.substring(imagUrl.indexOf('/')+1)
                                // }
                                $('#btnUpload1Syns_path').html('<img src="' + imagUrl + '" style="height: 135px;width: 135px" />');
                                $('#pictureSyns').val(imagUrl);
                            } else if (res.code == 502) {
                                return location.replace('admin/login.html');
                            } else {
                                layer.msg(res.msg, {icon: 2});
                            }
                        }
                    });

                    admin.req('enterprise/product/admin/productDetail/getProductDetailByProductId', {productId: data.id}, function (res) {

                        subData = res.data;
                        subData.forEach((emel, index) => {
                            emel.platformSkuCode = data.enterpriseCode + "_" + emel.skuCode
                        })
                        //展示SKU信息
                        createSkuTable(subData, data);
                    });


                }
            })

        }

        function createEnterpriseProductAttr(data) {
            let html = '';
            if (!data || data == null) {
                return;
            }
            for (let i = 0; i < data.length; i++) {
                //多选
                if (data[i].style == 'many') {
                    html += '<div style="margin-top: 20px" name="attrValue' + data[i].name + '">';
                    html += '<div class="layui-form-item">';
                    html += '<label class="layui-form-label" style="padding-left: 0;text-align: left;">' + data[i].name + ':</label>';
                    html += '<div class="layui-input-block">';

                    for (let j = 0; j < data[i].productAttributeValue.length; j++) {
                        var subData = data[i].productAttributeValue[j];
                        html += '<input lay-filter="enterpriseProductAttrValue' + data[i].id + '" type="checkbox" name  = "enterpriseProductAttrValue' + data[i].id + '"  value="' + subData.id + '" lay-skin="primary" title="' + subData.value + '" disabled>';
                    }
                    html += '</div>';
                    html += '</div>';
                    html += '</div>';
                }
                //单选
                if (data[i].style == 'single') {
                    html += '<div style="margin-top: 20px" name="attrValue' + data[i].name + '">';
                    html += '<div class="layui-form-item">';
                    html += '<label class="layui-form-label" style="padding-left: 0;text-align: left;">' + data[i].name + ':</label>';
                    html += '<div class="layui-input-block">';
                    html += '<select lay-filter="enterpriseProductAttrValue' + data[i].id + '"  name="enterpriseProductAttrValue' + data[i].id + '" id="enterpriseProductAttrValue' + data[i].id + '" lay-verify="required" disabled>';
                    html += '<option value="">请选择属性</option>';
                    for (let j = 0; j < data[i].productAttributeValue.length; j++) {
                        var subData = data[i].productAttributeValue[j];
                        html += '<option value="' + subData.id + '">' + subData.value + '</option>';
                    }
                    html += "</select>";
                    html += '</div>';
                    html += '</div>';
                    html += '</div>';
                }
                //文本
                if (data[i].style == 'text') {
                    html += '<div style="margin-top: 20px" name="attrValue' + data[i].name + '">';
                    html += '<div class="layui-form-item">';
                    html += '<label class="layui-form-label" style="padding-left: 0;text-align: left;">' + data[i].name + ':</label>';
                    html += '<div class="layui-input-block">';
                    html += '<input type="text" class="layui-input" lay--filter="enterpriseProductAttrValue' + data[i].id + '" name="enterpriseProductAttrValue' + data[i].id + '" id="enterpriseProductAttrValue' + data[i].id + '" lay-verify="required" disabled/>';
                    html += '</div>';
                    html += '</div>';
                    html += '</div>';
                }
            }
            //console.log(html);
            $("[name='enterpriseProductAttrHtml']").html(html);
            form.render();

        }
//   新 添加自采商品
        function showAddSelfCollectedGoods(_data) {
            admin.open({
                type: 1,
                area: ["1800px", '800px'],
                offset: '65px',
                title: _data ? '修改自采物料' : '添加自采物料',
                content: $('#addSelfCollectedGoods').html(),
                success: function () {
                    let addSelfCollectedGoodsTableListData = [], specificationCode = [],
                        addSelfCollectedGoodsTableListProductPack = [], addSelfCollectedGoodsTableListProductUnit = [],
                        isBaseUnitProductUnit = '';
                    let getProductInfoBySkuCodeData = '';
                    let cacheParameters = {productTypeId: '', addSelfCollectedGoodsNum: 0}; //保存请求参数,防止同一参数多次请求

                    let selectedData = function (treeData, targetId) {
                        for (var k = 0; k < treeData.length; k++) {
                            var nodeId = treeData[k].id;
                            if (targetId == nodeId) {
                                treeData[k].selected = true;
                                return;
                            } else {
                                if (treeData[k].children && treeData[k].children != '') {
                                    selectedData(treeData[k].children, targetId);
                                }
                            }
                        }
                    };

                    //请求物料类型
                    admin.reqSync('enterprise/product/admin/productType/getProductTypeByType', {type: '0'}, res => {
                        if (res.code === 200) {
                            loadAddSelfCollectedGoodsSelectHtml(res.data, '请选择类型', 'addSelfCollectedGoodsProductTypeId', 1)
                        }
                    }, 'GET');


                    //请求品牌
                    admin.reqSync('enterprise/product/admin/productBrand/getAllProductBrandByType', {type: '0'}, res => {
                        if (res.code === 200) {
                            loadAddSelfCollectedGoodsSelectHtml(res.data, '请选择类型', 'addSelfCollectedGoodsBrandId', 1)
                        }
                    }, 'GET');

                    //请求物料系列
                    admin.reqSync('enterprise/product/admin/product/getAllProductByType', {type: '0'}, res => {
                        if (res.code === 200) {
                            loadAddSelfCollectedGoodsSelectHtml(res.data, '请选择类型', 'addSelfCollectedGoodsProductId', 2)
                        }
                    }, 'GET');




                    if (_data) {
                        $('#addSelfCollectedGoodsProductTypeId').attr('disabled', 'disabled');
                        $('#addSelfCollectedGoodsBrandId').attr('disabled', 'disabled');
                        $('.addSelfCollectedGoodsForm input[name="name"]').attr('disabled', 'disabled');
                        $('.addSelfCollectedGoodsForm input[name="productCode"]').attr('disabled', 'disabled');
                        $('.addSelfCollectedGoodsNumBox').hide();
                        $('.addSelfCollectedGoodsPictureBox').hide();
                        $('.addSelfCollectedGoodsForm select').removeAttr('lay-verify');
                        $('.addSelfCollectedGoodsForm input').removeAttr('lay-verify');
                        $('#addSelfCollectedGoodsTableModifyListUploadImg').val(_data.productPic);
                        $('#addSelfCollectedGoodsTableModifyListUploadImg_path').html('<img src="' + _data.productPic + '"/>');

                        //规格数据
                        admin.reqSync('enterprisecab/productCab/admin/productDetail/getProductInfoBySkuCode', {skuCode: _data.skuCode}, function (res) {
                            if (res.code === 200) {
                                getProductInfoBySkuCodeData = res.data;
                                getProductInfoBySkuCodeData.addSelfCollectedGoodsProductTypeId = getProductInfoBySkuCodeData.productTypeId;
                                getProductInfoBySkuCodeData.addSelfCollectedGoodsBrandId = getProductInfoBySkuCodeData.brandId;
                                getProductInfoBySkuCodeData.name = getProductInfoBySkuCodeData.productName;
                                getProductInfoBySkuCodeData.productCode = getProductInfoBySkuCodeData.productCode;

                                //规格数据
                                admin.reqSync('enterprise/product/admin/productSpec/getProductSpecByProductTypeId', {productTypeId: getProductInfoBySkuCodeData.addSelfCollectedGoodsProductTypeId}, function (res) {
                                    if (res.code === 200) {
                                        getProductInfoBySkuCodeData.specificationCode = res.data;
                                    }
                                }, 'get');

                                //包装方案
                                admin.reqSync('enterprise/product/admin/productPack/getByProductTypeId', {productTypeId: getProductInfoBySkuCodeData.addSelfCollectedGoodsProductTypeId}, function (res) {
                                    if (res.code === 200) {
                                        getProductInfoBySkuCodeData.addSelfCollectedGoodsTableListProductPack = res.data;
                                    }
                                }, 'get');

                                // 包装单位
                                admin.reqSync('enterprise/product/admin/productUnit/getProductUnitByType', {
                                    type: 0,
                                    productTypeId: getProductInfoBySkuCodeData.addSelfCollectedGoodsProductTypeId
                                }, function (res) {
                                    if (res.code === 200) {
                                        getProductInfoBySkuCodeData.addSelfCollectedGoodsTableListProductUnit = res.data;
                                    }
                                }, 'get');

                                admin.reqSync('enterprise/product/admin/productUnit/getIsBaseUnitProductUnitByType', {
                                    type: 0,
                                    productTypeId: getProductInfoBySkuCodeData.addSelfCollectedGoodsProductTypeId
                                }, res => {
                                    if (res.code === 200) {
                                        getProductInfoBySkuCodeData.isBaseUnitProductUnit = res.data.name || '';
                                    }
                                }, 'get');


                            }
                        }, 'get');


                    } else {

                        $('.addSelfCollectedGoodsTableModifyListUploadImgBox').hide();
                        form.on("select(addSelfCollectedGoodsProductTypeId)", function (data) {
                            if ($('#addSelfCollectedGoodsProductTypeId').val() == '') {
                                layer.msg('请选择类型', {icon: '5'})
                            }  else {
                                //请求物料单位
                                admin.reqSync('enterprise/product/admin/productUnit/getProductUnitByType', {type: '0',productTypeId:$("#addSelfCollectedGoodsProductTypeId").val()}, res => {
                                    if (res.code === 200) {
                                        loadAddSelfCollectedGoodsSelectHtml(res.data, '请选择物料单位', 'addSelfCollectedGoodsUnitId', 1)
                                    }
                                }, 'GET');
                                layer.load(2);
                                if (cacheParameters.productTypeId == $('#addSelfCollectedGoodsProductTypeId').val()) {
                                    addSelfCollectedGoodsTableListData.push({
                                        index: i,
                                        isShow: true,
                                        specificationCode: specificationCode,
                                        addSelfCollectedGoodsTableListProductPack: addSelfCollectedGoodsTableListProductPack,
                                        addSelfCollectedGoodsTableListProductUnit: addSelfCollectedGoodsTableListProductUnit,
                                        isBaseUnitProductUnit: isBaseUnitProductUnit,
                                        skuCode: '',
                                        skuName: '',
                                        oldSkuCode: '',
                                        oldSpecCode: '',
                                        marketPrice: '',
                                        packId: {name: '', id: ''},
                                        unitId: {name: '', id: ''},
                                        weightNumber:'',
                                        skuSpecValueNames: []
                                    })
                                } else {
                                    cacheParameters.productTypeId = $('#addSelfCollectedGoodsProductTypeId').val();
                                    specificationCode = [];
                                    addSelfCollectedGoodsTableListProductPack = [];
                                    addSelfCollectedGoodsTableListData = [];
                                    addSelfCollectedGoodsTableListProductUnit = [];
                                    isBaseUnitProductUnit = '';
                                    //规格数据
                                    admin.reqSync('enterprise/product/admin/productSpec/getProductSpecByProductTypeId', {productTypeId: $('#addSelfCollectedGoodsProductTypeId').val()}, res => {
                                        if (res.code === 200) {
                                            specificationCode = res.data;
                                        }
                                    }, 'get');

                                    //包装方案
                                    admin.reqSync('enterprise/product/admin/productPack/getByProductTypeId', {productTypeId: $('#addSelfCollectedGoodsProductTypeId').val()}, res => {
                                        if (res.code === 200) {
                                            addSelfCollectedGoodsTableListProductPack = res.data;
                                        }
                                    }, 'get');

                                    // 包装单位
                                    admin.reqSync('enterprise/product/admin/productUnit/getProductUnitByType', {
                                        type: 0,
                                        productTypeId: $('#addSelfCollectedGoodsProductTypeId').val()
                                    }, res => {
                                        if (res.code === 200) {
                                            addSelfCollectedGoodsTableListProductUnit = res.data;
                                        }
                                    }, 'get');

                                    //基础单位
                                    admin.reqSync('enterprise/product/admin/productUnit/getIsBaseUnitProductUnitByType', {
                                        type: 0,
                                        productTypeId: $('#addSelfCollectedGoodsProductTypeId').val()
                                    }, res => {
                                        if (res.code === 200) {
                                            isBaseUnitProductUnit = res.data.name || '';
                                        }
                                    }, 'get');

                                    for (let i = 0; i < 1; i++) {
                                        addSelfCollectedGoodsTableListData.push({
                                            index: i,
                                            isShow: true,
                                            specificationCode: specificationCode,
                                            addSelfCollectedGoodsTableListProductPack: addSelfCollectedGoodsTableListProductPack,
                                            addSelfCollectedGoodsTableListProductUnit: addSelfCollectedGoodsTableListProductUnit,
                                            isBaseUnitProductUnit: isBaseUnitProductUnit,
                                            skuCode: '',
                                            skuName: '',
                                            oldSkuCode: '',
                                            oldSpecCode: '',
                                            marketPrice: '',
                                            packId: {name: '', id: ''},
                                            unitId: {name: '', id: ''},
                                            weightNumber:'',
                                            skuSpecValueNames: []
                                        })
                                    }
                                }


                                table.reload('addSelfCollectedGoodsTableList', {data: addSelfCollectedGoodsTableListData});

                                layer.closeAll('loading');
                            }
                        })
                        $('#addSelfCollectedGoodsPictureBtn').click(uploadImg('addSelfCollectedGoodsPictureBtn', 'addSelfCollectedGoodsPicture_path', 'addSelfCollectedGoodsPicture'));
                    }


                    // 请求物料分类
                    let arr2tree;
                    admin.reqSync('enterprise/product/admin/productCategory/getProductCategoryByType', {type: 0}, function (res) {
                        for (let i = 0; i < res.data.length; i++) {
                            res.data[i].children = [];
                        }
                        arr2tree = xmSelect.arr2tree(res.data, "parentId", "id", "children", -1);
                    }, 'get', false);
                    selectedData(arr2tree, getProductInfoBySkuCodeData.productCategoryId);

                    let smlSelectInstans = xmSelect.render({
                        el: '#addSelfCollectedGoodsProductCategoryId',
                        model: {label: {type: 'text'}},
                        radio: true,
                        clickClose: true,
                        filterable: true,
                        tree: {
                            show: true,
                            strict: false,
                            expandedKeys: [-1],
                        },
                        tips: '顶级分类',
                        prop: {
                            name: 'name',
                            value: 'id',
                            children: 'children'
                        },
                        data() {
                            //填充数据
                            return arr2tree;
                        },
                        on(data) {
                            let parentId = data.arr.length > 0 ? data.change[0].id : -1;
                            $("input[name='addSelfCollectedGoodsProductCategoryId']").val(parentId);
                        }
                    });


                    if (_data) {
                        form.val('addSelfCollectedGoodsForm', getProductInfoBySkuCodeData);
                        let addSelfCollectedGoodsTbModifyList = table.render({
                            elem: '#addSelfCollectedGoodsTableModifyList',
                            page: false,
                            cellMinWidth: 115,
                            data: [getProductInfoBySkuCodeData],
                            cols: [[
                                {
                                    field: 'skuName',
                                    title: '物料规格名称',
                                    templet: d => '<input type="text" name="skuName" class="layui-input" lay-verify="required" value="' + d.skuName + '">'
                                },
                                {
                                    field: 'oldSkuCode',
                                    title: '旧料号',
                                    templet: d => '<input type="text" name="oldSkuCode" class="layui-input" value="' + d.oldSkuCode + '">'
                                },
                                {
                                    field: 'oldSpecCode',
                                    title: '旧规格码',
                                    templet: d => '<input type="text" name="oldSpecCode" class="layui-input" lay-verify="required" value="' + d.oldSpecCode + '">'
                                },
                                {
                                    field: 'skuSpecValueNames', title: '规格码', width: '550', templet: d => {
                                        let selectHTML = '', selectArray = d.skuSpecValue.split("_"), lastValue = '',
                                            beforeValue = '';
                                        d.specificationCode.forEach((item, index) => {
                                            selectHTML += '<div class="skuSpecValueNames" style="width: 130px;float: left;margin-right: 5px;margin-top: 5px;" ><select name="' + d.index + '-' + item.id + '" id="' + d.index + '-' + item.id + '">';
                                            selectHTML += '<option value="">' + item.name + '</option>';
                                            lastValue = '';
                                            beforeValue = '';
                                            if (item.specCode == 'is') {
                                                if (item.specLocation == 'last') {
                                                    lastValue = item.specHead

                                                } else if (item.specLocation == 'before') {
                                                    beforeValue = item.specHead
                                                }
                                            }
                                            item.productSpecValueList.forEach(itemList => {
                                                if (selectArray[index] == itemList.id) {
                                                    selectHTML += '<option value="' + itemList.id + '" skuSpec="' + item.id + '" selected="">' + beforeValue + itemList.value + lastValue + '</option>'
                                                } else {
                                                    selectHTML += '<option value="' + itemList.id + '" skuSpec="' + item.id + '" >' + beforeValue + itemList.value + lastValue + '</option>'
                                                }
                                            });

                                            selectHTML += '</select></div>';

                                        });
                                        return selectHTML;
                                    }
                                },
                                {field: 'isBaseUnitProductUnit', title: '基础计量单位'},
                                {
                                    field: 'marketPrice',
                                    title: '单价',
                                    templet: d => '<input type="text" name="marketPrice" class="layui-input" lay-verify="" value="' + d.marketPrice + '">'
                                },
                                {
                                    field: 'unitId', title: '包装单位', templet: d => {
                                        let selectHTML = '';
                                        selectHTML += '<select name="unitId">';
                                        selectHTML += '<option value="">包装单位</option>';
                                        d.addSelfCollectedGoodsTableListProductUnit.forEach(item => {
                                            if (d.unitId == item.id) {
                                                selectHTML += '<option value="' + item.id + '" selected="">' + item.name + '</option>';
                                            } else {
                                                selectHTML += '<option value="' + item.id + '">' + item.name + '</option>';
                                            }

                                        });
                                        selectHTML += '</select>';
                                        return selectHTML
                                    }
                                },
                                {
                                    field: 'packId', title: '包装方案', templet: d => {
                                        let selectHTML = '';
                                        selectHTML += '<select name="packId" lay-filter="packId">';
                                        selectHTML += '<option value="">包装方案</option>';
                                        d.addSelfCollectedGoodsTableListProductPack.forEach(item => {
                                            if (d.packId == item.id) {
                                                selectHTML += '<option value="' + item.id + '" selected="">' + item.name + '</option>';
                                            } else {
                                                selectHTML += '<option value="' + item.id + '">' + item.name + '</option>';

                                            }
                                        });
                                        selectHTML += '</select>';

                                        return selectHTML
                                    }
                                },

                            ]]
                        });

                        $('#addSelfCollectedGoodsTableModifyListUploadImgBtn').click(uploadImg('addSelfCollectedGoodsTableModifyListUploadImgBtn', 'addSelfCollectedGoodsTableModifyListUploadImg_path', 'addSelfCollectedGoodsTableModifyListUploadImg'));
                        form.on('submit(addSelfCollectedGoodsSubmit)', d => {
                            let rowModify = $("[lay-id=addSelfCollectedGoodsTableModifyList] table tbody tr").eq(0);
                            let skuString = '', skuSpecValueString = '', skuSpecString = '',
                                addSelfCollectedGoodsTableModifyListData = {};
                            for (let j = 0; j < rowModify.find('.skuSpecValueNames select').length; j++) {
                                if (rowModify.find(".skuSpecValueNames input").eq(j).val() == '') {
                                    skuString = '';
                                    skuSpecValueString = '';
                                    skuSpecString = '';
                                } else {
                                    skuString += rowModify.find(".skuSpecValueNames input").eq(j).val() + '-';
                                    skuSpecValueString += rowModify.find(".skuSpecValueNames option:selected").eq(j).val() + '_';
                                    skuSpecString += rowModify.find(".skuSpecValueNames option:selected").eq(j).attr('skuspec') + '_';
                                }

                            }


                            addSelfCollectedGoodsTableModifyListData.id = getProductInfoBySkuCodeData.id;
                            addSelfCollectedGoodsTableModifyListData.skuName = rowModify.find('input[name="skuName"]').val();
                            addSelfCollectedGoodsTableModifyListData.oldSkuCode = rowModify.find('input[name="oldSkuCode"]').val();
                            addSelfCollectedGoodsTableModifyListData.oldSpecCode = rowModify.find('input[name="oldSpecCode"]').val();
                            addSelfCollectedGoodsTableModifyListData.marketPrice = rowModify.find('input[name="marketPrice"]').val();
                            addSelfCollectedGoodsTableModifyListData.packId = rowModify.find('select[name="packId"]').val();
                            addSelfCollectedGoodsTableModifyListData.unitId = rowModify.find('select[name="unitId"]').val();
                            addSelfCollectedGoodsTableModifyListData.skuSpecValueNames = skuString.substring(0, skuString.length - 1);
                            addSelfCollectedGoodsTableModifyListData.skuSpecValue = skuSpecValueString.substring(0, skuSpecValueString.length - 1);
                            addSelfCollectedGoodsTableModifyListData.skuSpec = skuSpecString.substring(0, skuSpecString.length - 1);
                            addSelfCollectedGoodsTableModifyListData.productPic = $('#addSelfCollectedGoodsTableModifyListUploadImg').val();

                            layer.load(2);
                            admin.req('enterprisecab/cabProduct/admin/mostUsedKnifeList/updateProductDetailById', JSON.stringify(addSelfCollectedGoodsTableModifyListData), res => {
                                layer.closeAll('loading');
                                if (res.code === 200) {
                                    layer.closeAll();
                                    layer.msg(res.msg, {icon: 1});
                                    table.reload('commonToolCabinetTable');
                                } else {
                                    layer.msg(res.msg, {icon: 2});
                                }
                            }, 'put', true, 'application/json; charset=utf-8')
                        });

                    } else {
                        let addSelfCollectedGoodsTbList = table.render({
                            elem: '#addSelfCollectedGoodsTableList',
                            page: false,
                            cellMinWidth: 110,
                            data: addSelfCollectedGoodsTableListData,
                            limit: Number.MAX_VALUE,
                            height: 480,
                            cols: [[
                                {type: 'numbers', title: '序号'}
                                , {
                                    field: '',
                                    title: '物料编号',
                                    templet: d => {
                                        return `<input type="text" class="layui-input ${d.isShow == true ? '' : 'inputBorderNone'}" ${d.isShow == true ? '' : 'readonly'} name="skuCode" value="${d.skuCode}">
                                                <input type="hidden" name="isShow" value="${d.isShow}">`
                                    }
                                }
                                , {
                                    field: '', title: '物料规格名称', templet: d => {
                                        return `<input type="text" class="layui-input ${d.isShow == true ? '' : 'inputBorderNone'}" ${d.isShow == true ? '' : 'readonly'} name="skuName" value="${d.skuName}">`
                                    }
                                }
                                , {
                                    field: '', title: '旧料号', templet: d => {
                                        return `<input type="text" class="layui-input ${d.isShow == true ? '' : 'inputBorderNone'}" ${d.isShow == true ? '' : 'readonly'} name="oldSkuCode" value="${d.oldSkuCode}">`

                                    }
                                }
                                , {
                                    field: '', title: '旧规格码', templet: d => {
                                        return `<input type="text" class="layui-input ${d.isShow == true ? '' : 'inputBorderNone'}" ${d.isShow == true ? '' : 'readonly'} name="oldSpecCode" value="${d.oldSpecCode}">`
                                    }
                                }
                                , {
                                    field: '', title: '规格码', width: '550', templet: d => {
                                        let selectHTML = '', skuSpecValueNamesValue = '', skuSpecValueNamesString = '';
                                        d.skuSpecValueNames.forEach(item => skuSpecValueNamesString += item.name + '-');
                                        selectHTML += `<span style="display:${d.isShow == true ? 'none' : ''}">${skuSpecValueNamesString.substring(0, skuSpecValueNamesString.length - 1)}</span>`;

                                        d.specificationCode.forEach((item, index) => {
                                            let skuSpecValueNamesValueSelect = '';
                                            selectHTML += `<div class="skuSpecValueNames" style="width: 130px;float: left;margin:5px 5px 0 0; display:${d.isShow == true ? '' : 'none'}">
                                                       <select class="skuSpecValueNamesList"  name="${d.index + '-' + item.id}" id="${d.index + '-' + item.id}" style="margin-bottom: 5px" lay-search="">`;
                                            selectHTML += '<option value="">' + item.name + '</option>';
                                            if (d.skuSpecValueNames[index]) {
                                                skuSpecValueNamesValue = d.skuSpecValueNames[index].value;
                                            } else {
                                                skuSpecValueNamesValue = '';
                                            }
                                            item.productSpecValueList.forEach(itemList => {
                                                if (skuSpecValueNamesValue == itemList.id) {
                                                    skuSpecValueNamesValueSelect = 'selected=""'
                                                } else {
                                                    skuSpecValueNamesValueSelect = ''
                                                }
                                                if (item.specCode == 'is') {
                                                    if (item.specLocation == 'last') {
                                                        selectHTML += '<option ' + skuSpecValueNamesValueSelect + ' value="' + itemList.id + '" skuSpec="' + item.id + '" >' + itemList.value + item.specHead + '</option>'
                                                    } else {
                                                        selectHTML += '<option ' + skuSpecValueNamesValueSelect + ' value="' + itemList.id + '" skuSpec="' + item.id + '" >' + item.specHead + itemList.value + '</option>'
                                                    }

                                                } else {
                                                    selectHTML += '<option ' + skuSpecValueNamesValueSelect + ' value="' + itemList.id + '" skuSpec="' + item.id + '" >' + itemList.value + '</option>'
                                                }
                                            });

                                            selectHTML += '</select></div>';

                                        });
                                        return selectHTML;
                                    }
                                }
                                , {
                                    field: '', title: '单价', templet: d => {
                                        return `<input type="text" class="layui-input ${d.isShow == true ? '' : 'inputBorderNone'}" ${d.isShow == true ? '' : 'readonly'}
                                                name="marketPrice" value="${d.marketPrice}" onkeyup="value=value.replace(/^\\D*(\\d*(?:\\.\\d{0,2})?).*$/g, \'$1\')">`
                                    }
                                }
                                , {
                                    field: '',
                                    title: '基础计量单位',
                                    width: '100',
                                    align: 'center',
                                    templet: d => d.isBaseUnitProductUnit
                                }
                                , {
                                    field: '', title: '包装方案', templet: d => {
                                        let selectHTML = `<span style="display:${d.isShow == true ? 'none' : ''}">${d.packId.name}</span>`;
                                        selectHTML += `<div style="display:${d.isShow == true ? '' : 'none'}"><select name="packId">`;
                                        selectHTML += '<option value="">包装方案</option>';
                                        d.addSelfCollectedGoodsTableListProductPack.forEach(item => {
                                            if (d.packId.value && d.packId.value == item.id) {
                                                selectHTML += '<option value="' + item.id + '" selected="">' + item.name + '</option>';
                                            } else {
                                                selectHTML += '<option value="' + item.id + '">' + item.name + '</option>';
                                            }
                                        });
                                        selectHTML += '</select></div>';
                                        return selectHTML;
                                    }
                                }
                                , {
                                    field: '', title: '包装单位', templet: d => {
                                        let selectHTML = `<span style="display:${d.isShow == true ? 'none' : ''}">${d.unitId.name}</span>`;
                                        selectHTML += `<div style="display:${d.isShow == true ? '' : 'none'}"><select name="unitId">`;
                                        // selectHTML += '<option value="">包装单位</option>';
                                        d.addSelfCollectedGoodsTableListProductUnit.forEach(item => {
                                            if (d.unitId.value && d.unitId.value == item.id) {
                                                selectHTML += '<option value="' + item.id + '" selected="">' + item.name + '</option>';
                                            } else {
                                                selectHTML += '<option value="' + item.id + '">' + item.name + '</option>';
                                            }

                                        });
                                        selectHTML += '</select></div>';
                                        return selectHTML;
                                    }
                                },
                                {
                                    field: '', title: '重量', templet: d => {
                                        return `<input type="text" class="layui-input ${d.isShow == true ? '' : 'inputBorderNone'}" ${d.isShow == true ? '' : 'readonly'} name="weightNumber" value="${d.weightNumber}">`
                                    }
                                }
                                ,  {field: '', title: '操作', templet: '#addSelfCollectedGoodsTableListBar', width: '160'}

                            ]],
                            done: function (res, curr, count) {
                                if (res.data.length > 0) {
                                    res.data.forEach((item, index) => {
                                        if (item.addSelfCollectedGoodsTableListProductUnit.length > 0) {
                                            if (item.addSelfCollectedGoodsTableListProductUnit[0].name === undefined) {
                                                addSelfCollectedGoodsTableListData[index].unitId = {
                                                    name: item.addSelfCollectedGoodsTableListProductUnit[0].name,
                                                    value: item.addSelfCollectedGoodsTableListProductUnit[0].id
                                                }
                                            }
                                        }
                                    })
                                }
                                form.render('select');

                                $("body").delegate("[lay-id='addSelfCollectedGoodsTableList'] input[name='skuCode']", "change", function () {
                                    if(addSelfCollectedGoodsTableListData[$(this).parents('tr').index()]) {
                                        addSelfCollectedGoodsTableListData[$(this).parents('tr').index()].skuCode = $(this).val().trim();
                                    }
                                });
                                $("body").delegate("[lay-id='addSelfCollectedGoodsTableList'] input[name='skuName']", "change", function () {
                                    if(addSelfCollectedGoodsTableListData[$(this).parents('tr').index()]) {
                                        addSelfCollectedGoodsTableListData[$(this).parents('tr').index()].skuName = $(this).val().trim();
                                    }
                                });
                                $("body").delegate("[lay-id='addSelfCollectedGoodsTableList'] input[name='oldSkuCode']", "change", function () {
                                    if(addSelfCollectedGoodsTableListData[$(this).parents('tr').index()]) {
                                        addSelfCollectedGoodsTableListData[$(this).parents('tr').index()].oldSkuCode = $(this).val().trim();
                                    }
                                });
                                $("body").delegate("[lay-id='addSelfCollectedGoodsTableList'] input[name='oldSpecCode']", "change", function () {
                                    if(addSelfCollectedGoodsTableListData[$(this).parents('tr').index()]) {
                                        addSelfCollectedGoodsTableListData[$(this).parents('tr').index()].oldSpecCode = $(this).val().trim();
                                    }

                                });
                                $("body").delegate("[lay-id='addSelfCollectedGoodsTableList'] input[name='marketPrice']", "change", function () {
                                    if(addSelfCollectedGoodsTableListData[$(this).parents('tr').index()]) {
                                        addSelfCollectedGoodsTableListData[$(this).parents('tr').index()].marketPrice = $(this).val().trim();
                                    }

                                });
                                $("body").delegate("[lay-id='addSelfCollectedGoodsTableList'] input[name='weightNumber']", "change", function () {
                                    if(addSelfCollectedGoodsTableListData[$(this).parents('tr').index()]) {
                                        addSelfCollectedGoodsTableListData[$(this).parents('tr').index()].weightNumber = $(this).val().trim();
                                    }
                                });
                            }

                        });





                        form.on("select", function (data) {
                            if ($(data.elem).attr('name') == 'packId') {
                                addSelfCollectedGoodsTableListData[$(data.elem).parents('tr').index()].packId = {
                                    name: data.elem[data.elem.selectedIndex].text,
                                    value: data.value
                                }
                            } else if ($(data.elem).attr('name') == 'unitId') {
                                addSelfCollectedGoodsTableListData[$(data.elem).parents('tr').index()].unitId = {
                                    name: data.elem[data.elem.selectedIndex].text,
                                    value: data.value
                                }
                            } else if ($(data.elem).attr('name') == 'unitId') {
                                addSelfCollectedGoodsTableListData[$(data.elem).parents('tr').index()].unitId = {
                                    name: data.elem[data.elem.selectedIndex].text,
                                    value: data.value
                                }
                            }else if ($(data.elem).attr('class') == 'skuSpecValueNamesList') {
                                addSelfCollectedGoodsTableListData[$(data.elem).parents('tr').index()].skuSpecValueNames[$(data.elem).parents('.skuSpecValueNames').index() - 1] = {
                                    name: data.elem[data.elem.selectedIndex].text,
                                    value: data.value
                                };
                            }
                        });
                        // 工具条点击事件
                        table.on('tool(addSelfCollectedGoodsTableList)', function (obj) {
                            let data = obj.data;
                            if (obj.event === 'save') {
                                console.log(addSelfCollectedGoodsTableListData)
                                if (addSelfCollectedGoodsTableListData[obj.data.index].skuCode == '') {
                                    layer.msg('请输入物料编号', {icon: "5"});
                                    return false
                                } else if (addSelfCollectedGoodsTableListData[obj.data.index].skuName == '') {
                                    layer.msg('请输入物料规格名称', {icon: "5"});
                                    return false

                                } else if (addSelfCollectedGoodsTableListData[obj.data.index].oldSpecCode == '') {
                                    layer.msg('请输入旧规格码', {icon: "5"});
                                    return false

                                } else if (addSelfCollectedGoodsTableListData[obj.data.index].marketPrice == '') {
                                    layer.msg('请输入单价', {icon: "5"});
                                    return false

                                }
                                addSelfCollectedGoodsTableListData[obj.data.index].isShow = false;
                                addSelfCollectedGoodsTbList.reload({data: addSelfCollectedGoodsTableListData});
                            } else if (obj.event === 'modify') {
                                addSelfCollectedGoodsTableListData[obj.data.index].isShow = true;
                                addSelfCollectedGoodsTbList.reload({data: addSelfCollectedGoodsTableListData});
                            }
                        });

                        form.on('submit(addSelfCollectedGoodsSubmit)', d => {
                            let row = $("[lay-id=addSelfCollectedGoodsTableList] table tbody tr");
                            let listData = [], listDataObj = {};
                            for (let i = 0; i < row.length; i++) {
                                if (row.eq(i).find("input[name='isShow']").val() == 'true') {
                                    continue;
                                }
                                let skuObj = {};
                                /*let skuCode = row.eq(i).find("input[name='skuCode']").val();
                                let skuName = row.eq(i).find("input[name='skuName']").val();*/
                                let skuCode =  $("#addSelfCollectedGoodsProductId").val();
                                let skuName =$("#addSelfCollectedGoodsProductId option:selected").text();
                                let oldSkuCode = row.eq(i).find("input[name='oldSkuCode']").val();
                                let oldSpecCode = row.eq(i).find("input[name='oldSpecCode']").val();
                                let skuString = '', skuSpecValueString = '', skuSpecString = '';
                                for (let j = 0; j < row.eq(i).find(".skuSpecValueNames").find('select').length; j++) {
                                    if (row.eq(i).find(".skuSpecValueNames").find('input').eq(j).val() == '') {
                                        skuString = '';
                                        skuSpecValueString = '';
                                        skuSpecString = '';
                                    } else {
                                        skuString += row.eq(i).find(".skuSpecValueNames").find('input').eq(j).val() + '-';
                                        skuSpecValueString += row.eq(i).find(".skuSpecValueNames").find('option:selected').eq(j).val() + '_';
                                        skuSpecString += row.eq(i).find(".skuSpecValueNames").find('option:selected').eq(j).attr('skuspec') + '_';
                                    }

                                }
                                let skuSpecValueNames = skuString.substring(0, skuString.length - 1);
                                let skuSpecValue = skuSpecValueString.substring(0, skuSpecValueString.length - 1);
                                let skuSpec = skuSpecString.substring(0, skuSpecString.length - 1);
                                let marketPrice = row.eq(i).find("input[name='marketPrice']").val();
                                let packId = row.eq(i).find("select[name='packId']").val();
                                let unitId = row.eq(i).find("select[name='unitId']").val();

                                skuObj = {
                                    skuCode: skuCode,
                                    skuName: skuName,
                                    oldSkuCode: oldSkuCode,
                                    oldSpecCode: oldSpecCode,
                                    skuSpecValueNames: skuSpecValueNames,
                                    marketPrice: marketPrice,
                                    skuSpecValue: skuSpecValue,
                                    packId: packId,
                                    unitId: unitId,
                                    skuSpec: skuSpec

                                };
                                listData.push(skuObj)
                            }


                            listDataObj.productDetailForm = listData;
                            listDataObj.productTypeId = d.field.addSelfCollectedGoodsProductTypeId;
                            listDataObj.productCategoryId = d.field.addSelfCollectedGoodsProductCategoryId;
                            listDataObj.brandId = d.field.addSelfCollectedGoodsBrandId;
                            /*form.on('select(addSelfCollectedGoodsProductId)',function (data) {
                                alert(data);
                                console.log(data)
                            })*/
                            listDataObj.name = $("#addSelfCollectedGoodsProductId option:selected").text();
                            listDataObj.productCode = $("#addSelfCollectedGoodsProductId").val();
                            listDataObj.picture = d.field.addSelfCollectedGoodsPicture;
                            if (listDataObj.productDetailForm.length <= 0) {
                                layer.msg('请添加或保存规格列表', {icon: 2});
                                return false
                            }
                            layer.load(2);
                            admin.req('enterprisecab/cabProduct/admin/mostUsedKnifeList/addSelfPickProduct', JSON.stringify(listDataObj), res => {
                                layer.closeAll('loading');
                                if (res.code === 200) {
                                    layer.closeAll();
                                    layer.msg(res.msg, {icon: 1});
                                    table.reload('commonToolCabinetTable');
                                } else {
                                    layer.msg(res.msg, {icon: 2});
                                }
                            }, 'POST', true, 'application/json; charset=utf-8')
                        });
                    }
                    form.render('select');
                }
            })
        }
        // 搜索
        form.on('submit(formSubSearchLog)', function (data) {
            insTb.reload({where: data.field,page: {curr: 1}},'data');
        });
//addSelfCollectedGoods
        function loadAddSelfCollectedGoodsSelectHtml(data, tips, htmltarget, type) {
            let html = ' <option value>' + tips + '</option>';
            if (!data || data == null) {
                return;
            }
            for (let i = 0; i < data.length; i++) {
                if (type == 1) {
                    html += `<option value='${data[i].id}' >${data[i].name}</option>`;
                }else if(type==2){
                    html += `<option value='${data[i].productCode}' name='${data[i].name}'>${data[i].name}</option>`;
                }
            }
            $("form.addSelfCollectedGoodsForm select[name='" + htmltarget + "']").html(html);
            form.render('select');
        }
        // 添加按钮点击事件
        $('#productDetailSKUBtnAdd').click(function () {
            showAddSelfCollectedGoods();
        });

        // 显示编辑弹窗
        function showEditModel(data) {
            admin.open({
                type: 1,
                area: '860px',
                offset: '65px',
                title: data ? '修改物料明细表' : '添加物料明细表',
                content: $('#productDetailSKUForm').html(),
                success: function () {
                    form.val('productDetailSKUForm', data);
                    // 表单提交事件
                    form.on('submit(productDetailSKUFormSubmit)', function (d) {
                        layer.load(2);
                        admin.req(data ? 'enterprise/product/admin/productDetailSKU/update' : 'enterprise/product/admin/productDetailSKU/add', d.field, function (res) {
                            layer.closeAll('loading');
                            if (res.code == 200) {
                                layer.msg(res.msg, {icon: 1});
                                table.reload('productDetailSKUTable');
                                layer.closeAll('page');
                            } else {
                                layer.msg(res.msg, {icon: 2});
                            }
                        }, data ? 'PUT' : 'POST');
                        return false;
                    });
                }
            });
        }

        // 显示入库弹窗
        function showStorageModel(data) {
            admin.open({
                type: 1,
                area: ['500px', '300px'],
                //offset: '65px',
                title: '入库',
                content: $('#storageForm').html(),
                success: function () {
                    form.val('storageForm', data.data);
                    //查询仓库
                    admin.req('enterprisecab/warehouse/admin/warehouse/getWarehouseVOAll', {}, function (res) {
                        if (res.code == 200) {
                            if (res.data.length > 0){
                                $.each(res.data,function (index,item) {
                                    $("#warehouseIdOption").append(new Option(item.name,item.id));
                                })
                                form.render('select');
                            }
                        } else {
                            layer.msg(res.msg, {icon: 2});
                        }
                    }, 'GET');
                    // 表单提交事件
                    form.on('submit(storageFormSubmit)', function (d) {
                        console.log(d.field)
                        layer.load(2);
                        admin.req('enterprise/order/admin/cabInventoryProduct/addCabInventoryProduct', JSON.stringify(d.field), function (res) {
                            layer.closeAll('loading');
                            if (res.code == 200) {
                                layer.msg(res.msg, {icon: 1});
                                table.reload('productDetailSKUTable');
                                layer.closeAll('page');
                            } else {
                                layer.msg(res.msg, {icon: 2});
                            }
                        },'POST', true, 'application/json; charset=utf-8');
                        return false;
                    });
                }
            });
        }
        // 删除
        function doDelete(obj) {
            layer.confirm('确定要删除吗？', {
                offset: '65px',
                skin: 'layui-layer-admin'
            }, function (i) {
                layer.close(i);
                layer.load(2);
                admin.req('enterprise/product/admin/productDetailSKU/' + obj.data.id, {}, function (res) {
                    layer.closeAll('loading');
                    if (res.code == 200) {
                        layer.msg(res.msg, {icon: 1});
                        obj.del();
                    } else {
                        layer.msg(res.msg, {icon: 2});
                    }
                }, 'DELETE');
            });
        }

        // 导出excel
        $('#productDetailSKUBtnExport').click(function () {
            var checkRows = table.checkStatus('productDetailSKUTable');
            if (checkRows.data.length == 0) {
                layer.msg('请选择要导出的数据', {icon: 2});
            } else {
                table.exportFile(insTb.config.id, checkRows.data, 'xls');
            }
        });
        // 上传图片
        function uploadImg(_elem, pathId, inputId) {
            upload.render({
                elem: '#' + _elem
                , url: config.upload_url + 'uploadFile'
                , data: {}
                , accept: 'file'
                , exts: 'jpg|png|RAR|zip|pdf|txt|doc|docx|xls|xlsx|ppt|pptx'
                , headers: {Authorization: 'Bearer ' + config.getToken()}
                , done: function (res) {
                    if (res.code == 200) {
                        layer.msg(res.msg, {icon: 1});
                        let imagUrl = res.data.url;
                        $('#' + pathId).html('<img src="' + imagUrl + '"/>');
                        $('#' + inputId).val(imagUrl);
                    } else if (res.code == 502) {
                        return location.replace('admin/login.html');
                    } else {
                        layer.msg(res.msg, {icon: 2});
                    }
                }
            });
        }
    });
</script>